#include "../../../common/etcd.hpp"
#include <gflags/gflags.h>
#include <unordered_map>
DEFINE_string (logfile, "etcd.log", "日志文件名");
DEFINE_int32 (loglevel, 0, "日志等级: 0-TRACE, 1-DEBUG, 2-INFO, 3-WARN, 4-ERROR, 5-FATAL");

unordered_map<int, spdlog::level::level_enum> m = { {0, spdlog::level::trace}, {1, spdlog::level::debug}, {2, spdlog::level::info}, {3, spdlog::level::warn}, {4, spdlog::level::err}, {5, spdlog::level::critical}
};

const std::string addr = "http://127.0.0.1:2379";



void put_cb(const std::string &key, const std::string &value) {
    LOG_INFO("收到服务注册通知: {} - {}", key, value);
}

void del_cb(const std::string &key, const std::string &value) {
    LOG_INFO("收到服务下线通知: {} - {}", key, value);
}




int main() {
    init_logger(FLAGS_logfile, m[FLAGS_loglevel]);
    // std::thread work([]()
    Discovery d_client(addr, "/server", put_cb, del_cb);
    std::thread work([]() {
        Registry r_client(addr);
        r_client.registry("/server/friend", "127.0.0.1:8080");
        r_client.registry("/server/chat", "127.0.0.1:7070");
        r_client.registry("/server/user", "127.0.0.1:6060");
    });
    // work.join();
    std::this_thread::sleep_for(std::chrono::seconds(15));
    return 0;
}